package com.noble.meether.ui.diamond;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.noble.glamour.ui.user.paygoods.GoodsConstant;
import com.noble.library.widget.RecyclerView.base.BaseRecyclerViewAdapter;
import com.noble.library.widget.RecyclerView.base.BaseRecyclerViewHolder;
import com.noble.meether.MeetUIShow;
import com.noble.meether.R;
import com.noble.meether.ui.diamond.bean.Diamond;

/**
 * 钻石列表
 */
public class MyDiamondAdapter extends BaseRecyclerViewAdapter<Diamond> {

    private Context mContext;

    public MyDiamondAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public int[] getItemLayouts() {
        return new int[]{R.layout.item_diamond_act};//钻石item布局
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return super.onCreateViewHolder(parent, viewType);
    }

    @Override
    public void onBindRecycleViewHolder(BaseRecyclerViewHolder viewHolder, int position) {
        MyViewHolder vh = new MyViewHolder(viewHolder);
        final Diamond info = getItem(position);
        vh.tv_num.setText(String.valueOf(info.getDoPay()));
        vh.tv_price.setText("￥" + info.getAmount());//价格
        vh.pay_new.setVisibility(info.isNew() ? View.VISIBLE : View.GONE);
        vh.pay_item.setOnClickListener(view -> {//跳转支付列表
            MeetUIShow.showPayTypeDlg((FragmentActivity) mContext, GoodsConstant.PAY_DIAMOND, info.getId(), "购买钻石" + info.getDoPay());
        });
    }

    @Override
    public int getRecycleViewItemType(int position) {
        return 0;
    }

    class MyViewHolder {
        TextView tv_num;
        TextView tv_price;
        RelativeLayout pay_item;
        ImageView pay_new;

        public MyViewHolder(BaseRecyclerViewHolder convertView) {
            initView(convertView);
        }

        private void initView(BaseRecyclerViewHolder convertView) {
            pay_item = convertView.findViewById(R.id.pay_item);
            tv_num = convertView.findViewById(R.id.tv_num);
            tv_price = convertView.findViewById(R.id.tv_money);
            pay_new = convertView.findViewById(R.id.pay_new);
        }
    }
}